// pages/orders/orders.js
Page({
  data: {
    orderDetails: []
  },

  onLoad: function () {
    this.getOrderDetails();
  },

  getOrderDetails: function () {
    wx.request({
      url: 'http://127.0.0.1:3000/getOrderDetails', // 请确保这是你的服务器地址
      method: 'GET',
      success: (res) => {
        if (res.data.success) {
          this.setData({
            orderDetails: res.data.orderDetails
          });
        } else {
          wx.showToast({
            title: '订单不存在',
            icon: 'none',
            duration: 2000
          });
        }
      },
      fail: () => {
        wx.showToast({
          title: '网络错误，请稍后再试',
          icon: 'none',
          duration: 2000
        });
      }
    });
  },

  handleOrderAction: function (event) {
    const action = event.currentTarget.dataset.action;
    wx.showToast({
      title: `处理订单操作: ${action}`,
      icon: 'none',
      duration: 2000
    });
  }
});